<?php
  function build_tree($cats,$parent_id,$prev_alies='',$only_parent = false){
    if(is_array($cats) and isset($cats[$parent_id])){
        $tree = '<ul class="menu">';
        if($only_parent==false){
            foreach($cats[$parent_id] as $cat){
                $prev_alies1 = $prev_alies .'/'. $cat['alies'];
                $tree .= '<li><a href="'. $prev_alies1 . '"> '.$cat['name'];
                $tree .=  build_tree($cats,$cat['id'],$prev_alies1);
                $tree .= '</li>';
            }
        }elseif(is_numeric($only_parent)){
            $cat = $cats[$parent_id][$only_parent];
            $tree .= '<li><a href="/'.$cat['alies']. '"> '.$cat['name'];
            $tree .=  build_tree($cats,$cat['id']);
            $tree .= '</li>';
        }
        $tree .= '</ul>';
    }
    else return null;
    return $tree;
}
?>